#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N=1e5+10;
int n,k;
vector<pair<int,int>> table[N];
int dep[N];
int fa[N][20];
ll path[N];
void dfs(int u,int father)
{
	dep[u]=dep[father]+1;
	fa[u][0]=father;
	for(auto& e:table[u])
	{
		if(e.first==father)
		{
			continue;
		}
		path[e.first]=path[u]+e.second;
		dfs(e.first,u);
		
	}
	
}

int lca(int x,int y)
{
	if(dep[x]<dep[y]) swap(x,y);
	for(int i=19;i>=0;i--)
	{
		if(dep[x]-dep[y]>=(1<<i))
		{
			x=fa[x][i];
		}
	}
	if(x==y)
	{
		return x;
	}
	
	for(int i=19;i>=0;i--)
	{
		if(fa[x][i]!=fa[y][i])
		{
			x=fa[x][i];
			y=fa[y][i];
		}
	}
	return fa[x][0];
}

ll dist(int x,int y)
{
	return path[x]+path[y]-2*path[lca(x,y)];
}
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n-1;i++)
	{
		int a,b,c;
		cin>>a>>b>>c;
		table[a].push_back({b,c});
		table[b].push_back({a,c});
	}
	int ver[k];
	for(int i=0;i<k;i++)
	{
		cin>>ver[i];
	}
	
	dfs(1,0);
	for(int i=1;i<=19;i++)
	{
		for(int u=1;u<=n;u++)
		{
			fa[u][i]=fa[fa[u][i-1]][i-1];
		}
	}
	ll sum=0;
	for(int i=0;i<=k-2;i++)
	{
		sum+=dist(ver[i],ver[i+1]);
	}
	
	cout<<sum-dist(ver[0],ver[1])<<" ";
	for(int i=1;i<=k-2;i++)
	{
		cout<<sum-dist(ver[i-1],ver[i])-dist(ver[i],ver[i+1])+dist(ver[i-1],ver[i+1])<<" ";
	}
	cout<<sum-dist(ver[k-2],ver[k-1])<<" ";
	
	
	
	
	
	return 0;
}